package com.example.zbh.dsliao.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zbh.dsliao.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by yaolin on 15/11/21.
 */
public class RVTypeAdapter extends RecyclerView.Adapter<RVTypeAdapter.MyViewHolder> {
    //private int images[];
    private Context context;
    private int[] images = {R.mipmap.type_one, R.mipmap.type_two,
            R.mipmap.type_three, R.mipmap.type_four};   //歌曲分类图片

    private String[] text = {"情歌", "红歌", "劲爆", "更多"};

    public RVTypeAdapter(Context context) {
        this.context = context;
    }


    public void addData(int images[]){
        this.images = images;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.list_music_type, parent,false);
        return new MyViewHolder(v);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if(images != null && images.length > 0){
            holder.imageView.setImageResource(images[position]);
            holder.typeTv.setText(text[position]);
        }

    }

    @Override
    public int getItemCount() {
        return images.length;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView;
        private TextView typeTv;


        public MyViewHolder(View itemView) {
            super(itemView);
            imageView  = (ImageView) itemView.findViewById(R.id.img);
            typeTv = (TextView) itemView.findViewById(R.id.typeTv);
        }
    }
}
